﻿

using System.Collections.Generic;
using UnityEngine;

namespace BridgeShips {
    public class BezierMoveEntrty  {
        private Vector3 oldPos;//旧的数据点
        private List<Vector3> m_Path;
        private Queue<Vector3> m_que;
        private float timer;
        private float timer1;
        public Vector3 OldPos {
            get {
                return oldPos;
            }

            set {
                oldPos = value;
            }
        }

        public List<Vector3> Path {
            get {
                if (m_Path==null) {
                    m_Path = new List<Vector3>();
                }
                return m_Path;
            }

            set {
                m_Path = value;
            }
        }

        public Queue<Vector3> Que {
            get {
                if (m_que==null) {
                    m_que = new Queue<Vector3>();
                }
                return m_que;
            }
            set {
                m_que = value;
            }
        }

        public bool GetPos(Vector3 pos,BezierCurve bezier) {
           
            timer += Time.deltaTime;
            //如果有位移变化
            if ((pos-oldPos).magnitude>0.2f) {
                //timer1 = 0;
                Path.Add( pos );
                //每三秒生成一次贝塞尔队列
                if (timer>=0.05f) {
                    Que = bezier.FindPath( 0.02f, Path );
                    Path.Clear();
                    OldPos = pos;//记录最后一个坐标点值
                    Path.Add( OldPos );
                    timer = 0;
                }
                return true;
            }
            return false;
        }
    }
}
